/*
 * TOP SECRET Copyright 2006-2015 Transsion.com All right reserved. This software is the confidential and proprietary
 * information of Transsion.com ("Confidential Information"). You shall not disclose such Confidential Information and
 * shall use it only in accordance with the terms of the license agreement you entered into with Transsion.com.
 */
package com.yunji.framework_template.orm.persistence.vo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * ClassName:CodeDTO <br/>
 * Date: 2018年10月16日 下午3:47:12 <br/>
 * 
 * @author fenglibin1982@163.com
 * @Blog http://blog.csdn.net/fenglibing
 * @version
 * @see
 */
@Data
@ApiModel(value = "code", description = "数据返回code")
public class DataDTO<T> {

    @ApiModelProperty(notes = "响应码", example = "200")
    int    code;
    @ApiModelProperty(notes = "详细解释")
    String desc;
    T      data;

    /**
     * 包装操作成功的响应
     * 
     * @param data
     * @return
     */
    public static <T> DataDTO<T> success(T data) {
        DataDTO<T> rtn = new DataDTO<T>();
        rtn.setCode(200);
        rtn.setData(data);
        return rtn;
    }

    /**
     * 包括操作失败的响应
     * 
     * @param code
     * @param desc
     * @return
     */
    public static <T> DataDTO<T> fail(int code, String desc) {
        DataDTO<T> rtn = new DataDTO<T>();
        rtn.setCode(code);
        rtn.setDesc(desc);
        return rtn;
    }
}
